<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('物管费')" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>楼层名：</label>
                            <select name="floorName" class="form-control" id="floorName" required>
                                <option value="">请选择</option>
                                <option th:each="a:${sysFloorList}" th:value="${a.floorName}" th:text="${a.floorName}"></option>
                            </select>
                        </li>
                        <li>
                            <label>公司名：</label>
<!--                            <input type="text" name="companyName"/>-->
                            <select name="companyName" class="form-control" id="companyName" required>
                                <option value="">请选择</option>
                                <option th:each="a: ${tenantInfoList}" th:text="${a.tenantName}" th:value="${a.tenantName}"></option>
                            </select>
                        </li>
                        <li>
                            <label>日期：</label>
                            <input autocomplete="off" type="text" id="etldt" name="etldt" placeholder="请填写日期"  />
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="query()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="generatePropertyFee()" shiro:hasPermission="sujian:propertyManagementFee:add">
                <i class="fa fa-plus"></i> 计算
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="sujian:propertyManagementFee:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="sujian:propertyManagementFee:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <!--<a class="btn btn-success" onclick="$.table.importExcel()" shiro:hasPermission="sujian:floorManagement:import">-->
                <!--<i class="fa fa-upload"></i> 导入-->
            <!--</a>-->
            <a class="btn btn-warning" onclick="exportExcel()" shiro:hasPermission="sujian:propertyManagementFee:export">
                <i class="fa fa-download"></i> 导出
            </a>

        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: bootstrap-fileinput-js" />
<th:block th:include="include :: select2-js" />
<script th:inline="javascript">
    var options;
    var prefix = ctx + "sujian/propertyManagementFee";
    function query() {
        if(options!=null&&options!=undefined){
            var params = $("#bootstrap-table").bootstrapTable('getOptions');
            $("#bootstrap-table").bootstrapTable('refresh', params);
        }else{
            options = {
                url: prefix + "/list",
                createUrl: prefix + "/calculate",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                importUrl: prefix + "/importData",
                importTemplateUrl: prefix + "/importTemplate",
                uniqueId:"properId",
                modalName: "物管费",
                columns: [{
                    checkbox: true
                },{
                    field: 'properId',
                    title: '物管费Id',
                    visible: false
                },{
                    field: 'num',
                    title: '序号',
                    visible: false
                },
                    {
                        field: 'floorName',
                        title: '楼层名'
                    },
                    {
                        field: 'companyName',
                        title: '公司名'
                    },
                    {
                        field: 'coveredArea',
                        title: '建筑面积'
                    },
                    {
                        field: 'propertyFee',
                        title: '物管费'
                    },
                    {
                        field: 'emptyArea',
                        title: '空关面积'
                    },
                    {
                        field: 'propertyEmptyFee',
                        title: '物管费_空关',
                        visible: false
                    },
                    {
                        field: 'areaSum',
                        title: '面积小计',
                        visible: false
                    },
                    {
                        field: 'propertySum',
                        title: '物管费小计'
                    },
                    {
                        field: 'updatetime',
                        title: '生成时间'
                    },
                    {
                        field: 'etldt',
                        title: '月份日期'
                    }
                ]
            };
            $.table.init(options);
        }
    }

    function generatePropertyFee() {
        layer.open({
            type:1,
            title:["选择计算物管费月份","font-size:18px"],
            area:["400px","180px"],
            shade:false,
            anim:3,
            shade:0.3,
            content:$("#etldtArea").html(),
            btn:['确认'],
            yes:function (index) {
                var etldt = $('#generateEtldt').val();
                if(etldt==null||etldt==""||etldt==undefined){
                    $.modal.alertError("请输入要计算物管费的年月")
                    return;
                }
                $.ajax({
                    cache : true,
                    type : "POST",
                    url : ctx+"sujian/propertyManagementFee/calculateValue",
                    data : {
                        "etldt": etldt
                    },
                    async : false,
                    error : function(request) {
                        $.modal.alertError("系统错误");
                    },
                    success : function(data) {

                        $.operate.successCallback(data);
                    }
                });
            }
        });

    }

    /*导出接口*/
    function exportExcel(){
        // var rows=$.table.selectColumns(table.options.uniqueId);
        // if (rows.length == 0) {
        //     $.modal.alertWarning("请至少选择一条记录");
        //     return;
        // };
        var etlDate = $("#etldt").val();
        if (null == etlDate || "undefined" == etlDate || "" == etlDate) {
            $.modal.msgError("请在页面选择日期，确定导出哪个年月的物管费信息。");
            return
        }
        $.modal.confirm("确认要导出选中的" + etlDate + "的数据吗?", function() {
            var url = table.options.exportUrl;
            var data = { "etldt": etlDate };
            $.modal.loading("正在导出数据，请稍后...");
            $.post(url,data,function (res) {
                if (res.code == web_status.SUCCESS) {
                    window.location.href = ctx + "common/download?fileName=" + encodeURI(res.msg) + "&delete=" + true;
                } else if (res.code == web_status.WARNING) {
                    $.modal.alertWarning(res.msg)
                } else {
                    $.modal.alertError(res.msg);
                }
                $.modal.closeLoading();
            })
        });
    }

</script>
</body>

<!-- 导入区域 -->
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="file" name="file"/>
            <div class="mt10 pt5">
                <input type="checkbox" id="updateSupport" name="updateSupport" title="如果参数已经存在，更新这条数据。"> 是否更新已经存在的参数数据
                &nbsp;	<a onclick="$.table.importTemplate()" class="btn btn-default btn-xs" shiro:hasPermission="sujian:propertyManagementFee:template"><i class="fa fa-file-excel-o"></i> 下载模板</a>
            </div>
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！！！
            </font>
        </div>
    </form>
</script>
<script type="text/template" id="etldtArea">
    <form class="mt20 mb10">
        <div style="margin: 20px;">
            <span style="color: red;">若选择月份已有物管费记录，将直接覆盖！</span>
            <input type="text" class="form-control" id="generateEtldt" placeholder="请输入要计算物管费月份（yyyyMM）">
        </div>
    </form>
</script>

</html>